#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
#include <unordered_set>
#include <iostream>
using namespace std;

 bool isHappy(int n) {
        vector<int> v;
        unordered_set<int> hash;
        //hash.insert(n);
        while (n != 1)
        {
            v.push_back(n % 10);
            n /= 10;
            if (n == 0)
            {
                for (auto e : v)
                {
                    n += e * e;
                }
                cout << n << endl;
                hash.insert(n);
                if (hash.find(n) != hash.end())
                    return false;
                v.erase(v.begin(), v.end());
            }
        }
        return true;
    }


int main()
{
    cout << isHappy(7) << endl;
    return 0l;
}